package site.zhouinfo.xml;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

/**
 * java对象与xml相互转换 用户
 *
 * @author zhou
 * @create 2017-08-15 16:40
 * @email zhouinfo@qq.com
 * @blog blog.zhouinfo.site
 */

@XmlAccessorType(XmlAccessType.FIELD)
// XML文件中的根标识
@XmlRootElement(name = "Users")
// 控制JAXB 绑定类中属性和字段的排序
@XmlType(propOrder = {"userId", "userName", "password", "birthday", "money", "goods"})
public class User implements Serializable {

    private static final long serialVersionUID = 1L;
    @XmlElementWrapper(name = "goodsList")
    public List<Goods> goods = new ArrayList<Goods>();
    private int userId;
    private String userName;
    private String password;
    private Date birthday;
    private BigDecimal money;

    public User() {

    }

    public User(int userId, String userName, String password, Date birthday, BigDecimal money) {
        this.userId = userId;
        this.userName = userName;
        this.password = password;
        this.birthday = birthday;
        this.money = money;
    }

    public User(int userId, String userName, String password, Date birthday, BigDecimal money, List<Goods> goods) {
        this.userId = userId;
        this.userName = userName;
        this.password = password;
        this.birthday = birthday;
        this.money = money;
        this.goods = goods;
    }

    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public BigDecimal getMoney() {
        return money;
    }

    public void setMoney(BigDecimal money) {
        this.money = money;
    }

    public List<Goods> getGoods() {
        return goods;
    }

    public void setGoods(List<Goods> goods) {
        this.goods = goods;
    }

    public void addGoods(Goods goods) {
        this.goods.add(goods);
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("{");
        sb.append("\"userId\":")
                .append(userId);
        sb.append(",\"userName\":\"")
                .append(userName).append('\"');
        sb.append(",\"password\":\"")
                .append(password).append('\"');
        sb.append(",\"birthday\":\"")
                .append(birthday).append('\"');
        sb.append(",\"money\":")
                .append(money);
        sb.append(",\"goods\":")
                .append(goods);
        sb.append('}');
        return sb.toString();
    }
}
